home *** CD-ROM | disk | FTP | other *** search
/ Keystone Learning XML: More On Content Modeling / Keystone learning XML More on Content Modeling.iso / Sample Files / Chapter 9 / EmployeeDataIsland2.asp next >
Encoding:
Text File  |  1999-12-09  |  3.5 KB  |  127 lines

  1. <%@ Language=VBScript%>
  2. <HTML>
  3. <HEAD>
  4. <META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
  5. <TITLE>Employees</TITLE>
  6.  
  7. <%
  8.     Dim oConn        ' ADO connection object.
  9.     Dim oRs            ' Employee recordset object.
  10.     Dim oRsPhone    ' Emp phone recordset object.
  11.     Dim strSql        ' SQL string.
  12.  
  13.     ' Establish a connection to the database.
  14.     Set oConn = Server.CreateObject("ADODB.Connection")
  15.     Call oConn.Open( "DSN=Employees;UID=Admin;PWD=;" )
  16.         
  17.     ' Open a recordset containing all of the employees.
  18.     Set oRs = Server.CreateObject("ADODB.Recordset")
  19.     strSql = "SELECT * FROM employees ORDER BY lastname, firstname"
  20.     Call oRs.Open( strSql, oConn )
  21.  
  22.  
  23.     Response.Write( "<XML ID=employees>" & vbCrLf )
  24.     Response.Write( "<employees>" & vbCrLf)
  25.  
  26.     ' Iterate through all of the employees in
  27.     ' the database and generate the appropriate
  28.     ' XML document that contains their information.    
  29.     While Not oRs.EOF
  30.     
  31.         ' Display all of the employee information
  32.         ' that is in the employee table.
  33.         Response.Write( "<employee>" & vbCrLf )
  34.         Response.Write( "    <name>" & vbCrLf )
  35.         Response.Write( "        <first>" & oRs("firstname") & "</first>" & vbCrLf )
  36.         Response.Write( "        <last>" & oRs("lastname") & "</last>" & vbCrLf )
  37.         Response.Write( "    </name>" & vbCrLf )
  38.         Response.Write( "    <position>" & oRs("position") & "</position>" & vbCrLf )
  39.         Response.Write( "    <phone>" & vbCrLf )
  40.         
  41.         ' Get the phone numbers for this employee
  42.         ' and generate the appropriate tags and content.
  43.         Set oRsPhones = Server.CreateObject("ADODB.Recordset")
  44.         strSql = "SELECT * FROM phonenumbers" ' WHERE phonetype = 'main' AND id = '" & oRs("id") & "'"
  45.         Call oRsPhones.Open( strSql, oConn )
  46.         
  47.         While Not oRsPhones.EOF
  48.             ' Generate the tag containing the appropriate
  49.             ' phone information (type and number)
  50.             Response.Write( "        <" & oRsPhones("phonetype") & ">" )
  51.             Response.Write( oRsPhones("phonenumber") )
  52.             Response.Write( "</" & oRsPhones("phonetype") & ">" & vbCrLf )
  53.             oRsPhones.MoveNext 
  54.         Wend
  55.  
  56.         Response.Write( "    </phone>" & vbCrLf )
  57.         Response.Write( "</employee>" & vbCrLf & vbCrLf )
  58.         oRs.MoveNext 
  59.     Wend
  60.     
  61.     oRsPhones.Close
  62.     oRs.Close
  63.     oConn.Close 
  64.     
  65.     Response.Write( "</employees>" & vbCrLf )
  66.     Response.Write( "</XML>" & vbCrLf & vbCrLf )
  67. %>
  68.  
  69. <SCRIPT LANGUAGE=javascript>
  70. <!--
  71. var xmlDoc;
  72.  
  73. function button1_onclick() 
  74. {
  75.     var xmlEmp = employees.documentElement.childNodes.item( select1.selectedIndex );
  76.     var xmlPos = xmlEmp.childNodes.item( 1 );
  77.     var xmlPhone = xmlEmp.childNodes.item( 2 );
  78.  
  79.     position.innerText = xmlPos.text;
  80.     phone.innerText = xmlPhone.childNodes.item(0).text;
  81. }
  82. //-->
  83. </SCRIPT>
  84. </HEAD>
  85.  
  86.  
  87. <BODY>
  88.  
  89.  
  90. <!-- Put the employee names within 
  91.      the combo box.
  92. -->
  93. <H2>Select an employee</H2>
  94. <SELECT id=select1 name=select1>
  95. <SCRIPT LANGUAGE=javascript>
  96. <!--
  97.     var xmlRoot = employees.documentElement;
  98.     var intTotal = xmlRoot.childNodes.length;
  99.     var xmlEmp;
  100.     var intCount;
  101.     
  102.     for ( intCount = 0;
  103.           intCount < intTotal;
  104.           intCount++ )
  105.     {
  106.         xmlEmp = xmlRoot.childNodes.item( intCount );
  107.         document.write( "<OPTION>" );
  108.         document.write( xmlEmp.childNodes.item( 0 ).text );
  109.         document.write( "</OPTION>" );
  110.     }
  111. //-->
  112. </SCRIPT>
  113. </SELECT>
  114.  
  115. <INPUT type="button" value="Go get it!" id=button1 name=button1 LANGUAGE=javascript onclick="return button1_onclick()">
  116.  
  117. <P>
  118. <TABLE WIDTH=100%>
  119.     <TR><TD WIDTH=10%><B>Position:</B>
  120.     <TD><SPAN ID=position></SPAN>
  121.     <TR><TD><B>Phone:</B>
  122.     <TD><SPAN ID=phone></SPAN>
  123. </TABLE>
  124.  
  125. </BODY>
  126. </HTML>
  127.